package com.example.spring.controller;

import com.example.spring.pojo.User;
import com.example.spring.util.RedisUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    private Logger logger = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    private User user;
    @Value("${com.user.address}")
    private String address;
    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("/hello")
    public String showHello() {
        logger.debug("日志输出 debug");
        logger.info("日志输出 info");
        return "hello world";
    }

    @RequestMapping("/user")
    public String showUser() {
        return user.getName() + "==" + user.getAge() + "==" + address;
    }

    @RequestMapping("/test1")
    public void addRedis() {
        redisUtil.set("test", 123456);
    }

    @RequestMapping("/test2")
    public Object getRedis() {
        return redisUtil.get("test");
    }

}
